package _2022.hot100._141_环形链表;

/**
 * @author： YHSimon
 * @date： 2022-05-03 09:49
 */
class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val=x;
        next=null;
    }
}
public class Solution {
    public boolean hasCycle(ListNode head){
        ListNode fast=head,slow=head;
        while(fast!=null&&slow!=null){
            fast=fast.next;
            slow=slow.next;
            if(fast!=null){
                fast=fast.next;
            }else{
                return false;
            }
            if(fast==slow){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        ListNode node=new ListNode(3);
        ListNode node1=new ListNode(2);
        ListNode node2=new ListNode(0);
        ListNode node3=new ListNode(-4);
        node.next=node1;
        // node1.next=node;
        // node2.next=node3;
        // node3.next=node1;
        System.out.println(s.hasCycle(node));
    }
}
